<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // function createInterator(items){
        //     var i = 0
        //     return{
        //         next(){
        //             return{
        //                 value: items[i++],
        //                 done: i>items.length
        //             }
        //         }
        //     }
        // }
        // var iterator = createInterator();
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());


        function createInterator() {
            console.log('第一步');
            yield 1;
            console.log('第二步');
            yield 2;
            console.log('第三步');
            yield 3;
            console.log(iter.next().value);
            return undefined;
        }

        var iterator = createInterator();
        console.log(iterator.next());
        console.log(iterator.next());
        console.log(iterator.next());
        console.log(iterator.next());

        function* CreateInterator1(items) {
            for (var i = 0; i < items.length; i++) {
                yield items[i];
            }
        }

        var iterator1 = createInterator1([1, 2, 3, 4, 5, 6, 7, 8]);
        console.log(iterator1.next());
        console.log(iterator1.next());
        console.log(iterator1.next());
        console.log(iterator1.next());
        console.log(iterator1.next());
        console.log(iterator1.next());
        console.log(iterator1.next());
        console.log(iterator1.next());

        var obj ={
            name : "eric",
            age : 100,
            sex : "man",
            [Symbol.iterator]: function* (){
                for (var i in obj){
                    yield obj[i]
                }
            }
        }

        var str = 'abcdefg'
        var arr = [1,2,3,4,5,6,7]

        var iter = obj[Symbol.iterator]()
        console.log(iter.next().value)
        console.log(iter.next().value)
        console.log(iter.next().value)
        console.log(iter.next().value)

        for(var i of obj){
            console.log(i)
        }

        var str1 = 'ababcb'
        // for(var i = 0;i<str1.length;i++){
        //     console.log(str1[i])
        // }
        var iter10 = str[Symbol.iterator]()
        console.log(iter10.next().value)
        console.log(iter10.next().value)
        console.log(iter10.next().value)
        console.log(iter10.next().value)
        console.log(iter10.next().value)
        console.log(iter10.next().value)
        console.log(iter10.next().value)
    </script>
</body>

</html>